'use strict';

/**
 * 搜索页
 *
 * dict为全局变量（dict.js），这里进行依赖注入
 */
angular.module('app').controller('searchCtrl',['dict', '$http', '$scope', function (dict, $http, $scope) {
    /**
     * 头部 搜索
     * @type {string}
     */
    $scope.name = '';
    $scope.search = function () {
        /**
         * 获取列表信息
         */
        $http.get('data/positionList.json?name=' + $scope.name).success(function (resp) {
            $scope.list = resp;
        });
    }
    $scope.search();

    $scope.sheet = {};

    /**
     * 导航
     * @type {[*]}
     */
    $scope.tabList = [{
        id:'city',
        name:'城市'
    },{
        id:'salary',
        name:'薪水'
    },{
        id:'scale',
        name:'公司规模'
    }];

    /**
     * 点击导航
     * @param id的值有：city、salary、scale
     * @param name的值有：城市、薪水、公司规模
     */
    var tabId = '';
    $scope.filterObj = {};
    $scope.tClick = function (id,name) {
        tabId = id;
        $scope.sheet.list = dict[id];//储存弹出框数据
        $scope.sheet.visible = true;//用于显示或隐藏
    }

    /**
     * 单击选择项
     * @param id
     * @param name
     */
    $scope.sClick = function (id,name) {
        // console.log(id,name);

        if(id){//有选择，替换导航的值
            angular.forEach($scope.tabList,function (item) {
                if(item.id === tabId){
                    item.name = name;
                }
            });

            //过滤器设置 tabId的值有：city  salary  scale
            $scope.filterObj[tabId + 'Id'] = id;

        }else{// 没有选择，进行还原

            //删除过滤器的值
            delete $scope.filterObj[tabId + 'Id'];

            angular.forEach($scope.tabList,function (item) {
                if(item.id === tabId){
                    switch (item.id){
                        case 'city':
                            item.name = '城市';
                            break;
                        case 'salary':
                            item.name = '薪水';
                            break;
                        case 'scale':
                            item.name = '公司规模';
                            break;
                        default:
                    }
                }
            })
        }
    }
}]);












